<?php

/*
 * litchicms
 * Copyright (C) 2010-5-24 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");

!is_file($filename = SYSTEM . 'cache/con_channels/' . $RT['v']['m'] . ".php") && msg("非法参数");
require $filename;

require 'main.fun.php';
$Db = openSQL();


/*
 * 根据优先级 从上至下 选择模板
 * 10  action (回复,评论)
 * 20  id   (文章id)
 * 30  category  (文章分类)
 * 40  m  (频道,模块)
 *
 * 模板类型
 * tpl 全局
 * listtpl 列表
 * viewtpl 详细内容
 *
 * 允许出现的组合
 * 1 m-xxx
 * 2 m-xxx-part-xxx
 * 3 m-xxx-part-xxx-id-xxx
 * 4 m-xxx-category-xxx
 * 5 m-xxx-category-xxx-id-xxx
 * 6 m-xxx-part-xxx-category-xxx
 * 7 m-xxx-part-xxx-category-xxx-id-xxx
 * 特殊的 Unavailable
 */


$PreValue = array();
if (empty($_GET['category'])) {
    $PreValue['category'] = array();
} else {
    $PreValue['category'] = COLL_c_data(array('cid' => $_GET['category'], 'partname' => $_GET['part']));
}

if (empty($_GET['id'])) {
    $PreValue['id'] = array();
} else {
    $PreValue['id'] = COLL_data();
}


/*
 * 页面域变量处理
 */
!empty($CURR['keywords']) && $BRK_SET['sitekeywords'].=" " . $CURR['keywords'];
!empty($CURR['pagevarset']) && is_array($CURR['pagevarset']) && $BRK_SET = array_merge($BRK_SET, $CURR['pagevarset']);

//模板可能值
//40 m 频道文件已经将其实现了
//30 category
!empty($PreValue['category']['ctpl']) && $CURR['listtpl'] = $PreValue['category']['ctpl'];
!empty($PreValue['category']['cviewtpl']) && $CURR['viewtpl'] = $PreValue['category']['cviewtpl'];
//20 id
!empty($PreValue['id']['viewtpl']) && $CURR['viewtpl'] = $PreValue['id']['viewtpl'];
//10 action Unavailable
//模板选择 默认
$BRK_GLOBAL['tempfile'] = $CURR['tpl'];
//当前页是列表?
if (!empty($_GET['category'])) { //!empty($_GET['category']) || 其他同级的
    //分类 页面域变量 暂未实现
    if (!empty($PreValue['category']['pagevarset']) && $PreValue['category']['pagevarset'] = unserialize($PreValue['category']['pagevarset'])) {
        $BRK_SET = array_merge($BRK_SET, $PreValue['category']['pagevarset']);
    }
    //分类 使用关键字 暂未实现
    if (!empty($PreValue['category']['keywords'])) {
        $BRK_SET['sitekeywords'].=" " . $PreValue['category']['keywords'];
    }
    $BRK_GLOBAL['tempfile'] = $CURR['listtpl'];
}
//当前页是详细内容?
if (!empty($_GET['id'])) {
    if (!empty($PreValue['id']['pagevarset']) && $PreValue['id']['pagevarset'] = unserialize($PreValue['id']['pagevarset'])) {
        $BRK_SET = array_merge($BRK_SET, $PreValue['id']['pagevarset']);
    }
    if (!empty($PreValue['id']['keywords'])) {
        $BRK_SET['sitekeywords'].=" " . $PreValue['id']['keywords'];
    }
    $BRK_GLOBAL['tempfile'] = $CURR['viewtpl'];
}

//是action?
//if (!empty($_GET['action'])) {
//    $BRK_GLOBAL['tempfile'] = $CURR['viewtpl'];
//}
//dump($BRK_SET);
!function_exists('template') && require 'template.fun.php';
include template($BRK_GLOBAL['tempfile'] . ".php");